<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.util.*" %>
<%@ include file="/page/taglibs.jsp" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<%@ include file="/adapter/adapter-bootstrap.jsp" %>
<script type="text/javascript">

	var baseTemplateEdit = "${ctx}/template/edit";
	var baseTemplateDelete="${ctx}/template/deleteSTemplateBase";
	var templateEditUrl = "",templateDeleteUrl="",  templateId = "";
	
	function rowClickAfter(rowIndex,curTemplateId) {

		templateId = curTemplateId;
		templateEditUrl = baseTemplateEdit + "?template_id=" + templateId;
		templateDeleteUrl=baseTemplateDelete+"?template_id=" + templateId;

		var  arrId = document.getElementsByName("check");
		arrId[rowIndex -1 ].checked=true;	
	}

	function doTemplateEdit(){
		if (templateId == "") {
			alert("请选择要编辑的模板！");
		} else {
			document.getElementById("linkPage").href = templateEditUrl;
			document.getElementById('linkPage').click();
		}
	}
	function doTemplateDelete(){
		if (templateId == "") {
			alert("请选择要删除的模板！");
		} else {
			if(p_del()){
			//Utils.forward(templateDeleteUrl);
			    $.ajax({
			        url:templateDeleteUrl,
			        type: "POST",      
			        dataType:"json",
			        async: false,
			        success: function(data) {
			        	if(data.flag>0){
				            alert("删除成功！");	
				            window.location.reload();
			        	}
			/* 	          $.each(data, function(index, element) {
			             window.location.reload();
			          }); */
			        },
			        error: function() {
			          alert("error");
			        }
			      });
			
			}
		}
	}
	
	function p_del() { 
		var msg = "您真的确定要删除吗？\n\n请确认！"; 
		if (confirm(msg)==true){ 
		return true; 
		}else{ 
		return false; 
		} 
	}
	
</script>
</head>
<body>
<div class="panel panel-default">
	<div class="panel-heading">
		<h3 class="panel-title">请输入查询条件</h3>
	</div>
<div class="panel-body">
	<form class="form-horizontal" role="form"  action="${pageContext.request.contextPath }/template/queryList">
	<input type="hidden"  id="type"  name="type"  value="${type}" />
		<div class="form-group">
			<label class="col-xs-1 control-label"
				for="templateid">模板标识</label>
		<div class="col-xs-3"><input class="input-sm form-control" id="templateid"  name="templateid"
			type="text" /></div>
			<label class="col-xs-1 control-label" for="templatename">模板名称</label>
		<div class="col-xs-3"><input class="input-sm form-control" id="templatename"  name="templatename"
			type="text" /></div>
		<div class="col-xs-3">
			<button type="submit" class="btn btn-default btn-sm"
			>查询</button>
		</div>
</div>
</form>
</div>
</div>
			<div class="op-btn">
				<input type="button" class="btn btn-default" value="创建模板"  onclick="Utils.forward('${ctx}/template/create?type=${type}');"/>
				<input type="button" class="btn btn-default" value="删除模板"  onclick="doTemplateDelete();"/>				 
				<input type="button" class="btn btn-default" value="编辑模板"  onclick="doTemplateEdit();"/> 
				<input type="button" class="btn btn-default" value="查看模板"  onclick="doTemplateEdit()"/>
				<a id="linkPage"  target="_blank"/></a>
			</div>	
<macms:table dataListName="stbList" pageMode="true">
	<macms:html id="ch" label="选择" innerHtml="<input type='radio' name='check' value='15'>"></macms:html>
	<macms:text id="template_id" label="模板标识" align="center"></macms:text>
	<macms:text id="template_name" label="模板名称" align="center"></macms:text>
	<macms:text id="template_adapter" label="模板适配" align="center" dictname="S_TEMPLATE_ADAPTER"></macms:text>
	<macms:text id="last_modify_date" label="最近修改日期" align="center"></macms:text>
	<macms:text id="long_desc" label="模板描述" align="center"></macms:text>
</macms:table>
<script type="text/javascript">
	var preRow = null;
	$('tbody tr').bind('click', function() {
	
		var rowIndex = $(this).prevAll().length+1;
		if(rowIndex <1) return;
		
		if(preRow != null){
			preRow.removeClass("active");
		}
		$(this).addClass("active");
		preRow = $(this);

		// 行单击后事件(传入行号，模板标识)
		rowClickAfter(rowIndex,
				$(this).find("td").eq(1).text());
	});
</script>
</body>
</html>
